Technical Q&As
QD 23 - Problem with PaintRgn on 256-color Screens (15-Sept-95)
Q In our application, the user can select an area of an
image and drag it around. I want to show this visually by inverting the region
under the current mouse coordinate as the user moves the mouse around.
Inverting the region is nice because I can invert it again to get the
unselected pixels back. It's not nice, however, in that a 50% gray color looks
the same when it's inverted. To fix this problem, I tried using PaintRgn with
an RGBForeColor of r,g,b = 0x8000 and a transfer mode of addOver. This works
great on 24-bit screens, but it seems that on 256-color screens, applying this
operation twice doesn't quite return to the original color. Am I going to have
to use a custom color search procedure?
A You get the results you want on direct devices but not on indexed ones, and
unless you're extremely lucky with your color table, this is how it will always
work. The problem is that the mode calculations are done with the actual RGB
values used (the ones available in the color table), not the ones you request.
On indexed devices there's almost always a difference between the two, so
unless your color table happens to have the exact color you request, there will
be "errors." This never happens on direct devices because all colors are
available -- the operations work on direct RGB values and are never mapped
through color tables.
The solution is either to set up your color tables or palettes to make sure you
get the results you want each time, or to install a custom color search
procedure if that's what you'd prefer.
Technical Q&As
Previous Question | Contents | Next Question